﻿using System;
using System.Configuration;

namespace Alex.Library.Log.Configuration
{
    /// <summary>
    /// 日志输出适配器元素
    /// </summary>
    public class FlushAdapterElement : ConfigurationElement
    {
        /// <summary>
        /// 日志输出适配器类型
        /// </summary>
        [ConfigurationProperty("type", IsRequired = true)]
        public string Type
        {
            get
            {
                return (string)this["type"];
            }
        }

        /// <summary>
        /// 获取适配器对象
        /// </summary>
        /// <returns></returns>
        public IFlushAdapter GetAdapterObject()
        {
            try
            {
                System.Type type = System.Type.GetType(this.Type);
                return (IFlushAdapter)System.Activator.CreateInstance(type);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
